/////////////////////////////////////////////////////////////////////
//
//  MOE Framework (Meta Object Encapsulation Framework)
//
//  Original Author: Wiksy Wang, 2011
//
/////////////////////////////////////////////////////////////////////

#ifndef MOE_NAME_NAMED_OBJECT_CACHE_MANAGER_H
#define MOE_NAME_NAMED_OBJECT_CACHE_MANAGER_H

#include <vector>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/unordered_map.hpp>

#include "../RawByteVector.h"

namespace MOE
{

namespace Name
{

class NamedObjectCacheManager : boost::noncopyable
{
public:
	typedef boost::function<void(void*)> CachedObjectHandler;

	static NamedObjectCacheManager& GetSingleton()
	{
		static NamedObjectCacheManager singleton;
		return singleton;
	}

	void RegisterHandler(const RawByteVector& objName, const CachedObjectHandler& handler);
	void Handle(const RawByteVector& objName, void* dataPtr);
	void ClearAllHandlers();

	bool HasUnhandled() const;

private:
	NamedObjectCacheManager();
	~NamedObjectCacheManager();

	typedef std::vector<CachedObjectHandler> HandlerList;
	typedef boost::unordered_map<RawByteVector, HandlerList> CachedObjectMap;

	CachedObjectMap _cachedObjectMap;
};

}

}

#endif
